package com.personal.book1.controller;

import com.personal.book1.component.ComponentTest;
import com.personal.book1.service.ServiceTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

@Controller
public class ControllerTest {

    private ServiceTest serviceTest;
    private ComponentTest componentTest;

    // 属性注入
//    @Autowired
//    private final ServiceTest serviceTest = new ServiceTest();


    @Autowired
    public void setServiceTest(ServiceTest serviceTest) {
        this.serviceTest = serviceTest;
    }

    @Autowired
    public void setComponentTest(ComponentTest componentTest) {
        this.componentTest = componentTest;
    }

    public void hello() {
        System.out.println("hello,ControllerTest");
        serviceTest.hello();
        componentTest.hello();
    }




    // 构造函数注入
    //    public ControllerTest() {
//    }

//    public ControllerTest(ServiceTest serviceTest) {
//        this.serviceTest = serviceTest;
//    }
//
//    @Autowired
//    public ControllerTest(ServiceTest serviceTest, ComponentTest componentTest) {
//        this.serviceTest = serviceTest;
//        this.componentTest = componentTest;
//    }
}
